﻿namespace Oddo.Concept.Crm.Client.ViewModels
{
    using System;
    using System.Reflection;
    using DevExpress.Xpf.Core;
    using Microsoft.Practices.Unity;
    using Oddo.Concept.Crm.Client.Properties;
    using Oddo.Concept.Crm.Common.Diagnostic;
    using Oddo.Concept.Crm.Common.Presentation.Interfaces;
    using Oddo.Concept.Crm.Common.Security;
    using Oddo.Concept.Crm.Common.ViewModels;
    using Oddo.Concept.Crm.Common.Interfaces;

    public class ShellViewModel : ViewModelBase, IMessageDisplayServices
    {
        private string _shellViewTitle;
        private string _discretMessage;

        private readonly string _defaultShellViewTitle = 
            string.Format("{0}", ((AssemblyTitleAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute))).Title);

        

        public ShellViewModel()
        {
            ThemeManager.ApplicationThemeName = Settings.Default.ThemeName;
            ThemeManager.ThemeChanged += (s, e) =>
                {
                    if (string.Equals(Settings.Default.ThemeName, e.ThemeName)) return;
                    Settings.Default.ThemeName = e.ThemeName;
                    Settings.Default.Save();
                };

            ShellViewTitle = _defaultShellViewTitle;
        }
        /// <summary>
        /// Obtient ou définit le gestionnaire de rapport d'erreur
        /// </summary>
        [Dependency]
        public IErrorReportManager ErrorReportManager { get; set; }
        /// <summary>
        /// Obtient ou définit le service d'authentification
        /// </summary>
        [Dependency]
        public IAuthenticationService AuthenticationService { get; set; }

        /// <summary>
        /// Obtient ou définit le titre de la fenetre du shell
        /// </summary>
        public string ShellViewTitle
        {
            get { return _shellViewTitle; }
            set
            {
                _shellViewTitle = value;
                NotifyPropertyChanged(() => ShellViewTitle);
            }
        }
        /// <summary>
        /// Obtient ou définit un message à afficher dans la status bar de la fenetre du shell
        /// </summary>
        public string DiscretMessage
        {
            get { return _discretMessage; }
            set
            {
                _discretMessage = value;
                NotifyPropertyChanged(() => DiscretMessage);
            }
        }


        #region IMessageDisplayServices
        public void ShowDiscret(string message)
        {
            this.DiscretMessage = message;
        }

        public void ShowMessage(string message, string title)
        {
        }

        public bool? ShowQuestion(string message, string title)
        {
            return null;
        }

        public void ShowError(string message, string title)
        {
        }

        public void ShowError(string message, string title, bool allowSendReport, Exception exception)
        {
        }

        #endregion
        
    }
}